#pragma once
#include "Common.h"

namespace vf
{
    class Base
    {
    public:
        Base()
        {
            //错误用法！构造和析构期间不要调用virtual
            // 不会下降到Derived，调用的仍然是Base::PrintType()，甚至对象的类型都是Base
            PrintType(); 
        }
        ~Base()
        {
            PrintType();
        }
        virtual void PrintType() 
        {
            cout << "Base::PrintType(): " << typeid(*this).name() << endl;
        }
    };

    class Derived : public Base
    {
    public:
        virtual void PrintType() override
        {
            cout << "Derived::PrintType(): " << typeid(*this).name() << endl;
            Base::PrintType();
        }
    };

    void Test_VirtualFunc()
    {
        Derived d;
        Base &bd = d;
        bd.PrintType();
    }
}